package com.example.Mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.pojo.Xs_bj;
import com.example.pojo.Xs_bjinfo;
import com.example.pojo.Xs_dd;
import com.example.pojo.Xs_ddx;

public interface Xs_ddDao {
	//新增订单主表    departname maker permitter
	@Insert("insert into salesorder(CustBillName,Sfhs,BillStatus,BillDate,Billno,CustBillNo,CustCurrency,ExchRate,SalesID,zje,permittersign,DepartName,Maker,Permitter) values(#{custbillname},#{sfhs},#{billstatus},#{billdate},#{billno},#{custbillno},#{custcurrency},#{exchrate},#{salesid},#{zje},#{permittersign},#{departname},#{maker},#{permitter})")
    public void savedd(Xs_dd xsdd);
	//新增订单详表 prodid
	@Insert("insert into salesorderinfo(Billno,ProdID,ProdName,ProdSize,UnitName,sQuantity,OldPrice,Discount,sPrice,Amount,TaxRate,TaxAmt,VRtotal,PreInDate,QtyRemain,FromNo,TranType) values(#{billno},#{prodid},#{prodname},#{prodsize},#{unitname},#{squantity},#{oldprice},#{discount},#{sprice},#{amount},#{taxrate},#{taxamt},#{vrtotal},#{preindate},#{qtyremain},#{fromno},#{trantype})")
	public void saveddx(Xs_ddx xsddx);
    
	//审核订单状态
	@Update("update salesorder set permittersign='已审核' where Billno=#{billno}")
	public void shenhe(@Param("billno") String billno);
	
	//反审核订单状态
	@Update("update salesorder set permittersign='未审核' where Billno=#{billno}")
	public void shenhe2(@Param("billno") String billno);
	//日期单号
	@Select("selec t max(Billno) from salesorder where BillDate like '%${BillDate}%' ")
	public String billno(@Param("BillDate") String BillDate);
	//查询主表
	 @Select("select * from salesorder LIMIT  #{size},1")
	 public List<Xs_dd> selxsdd(@Param("size") int size);
	
    //查询详表
	 @Select("select a.*,b.ProdId as Pid,b.ProdName as Pname from salesorderinfo a inner join materialzhu as b on a.ProdID=b.ProdId where a.Billno=#{Billno}")
	 public List<Xs_ddx> selxsddx(@Param("Billno") String Billno);
	 
	//总页数
	 @Select("select count(*) from salesorder")
	 int count (@Param("count") int count);
	//删除详表
	@Delete("delete from salesorderinfo where Billno=#{Billno}")
	public void delXs_dd(@Param("Billno") String Billno);
	//删除主表
	@Delete("delete from salesorder where Billno=#{Billno}")
	public void delXs_ddx(@Param("Billno") String Billno);
	
	
 
	
	//修改单况
	@Update("update salesorder set BillStatus='未结案' where billno=#{billno}")
	void updatexsddx(@Param("billno") String billno);
   
	@Update("update salesorder set BillStatus='已结案' where billno=#{billno}")
	void updatexsx(@Param("billno") String  billno);
	
	//转销售报价单  
	@Select("select v.prodid as Pid,v.prodname as Pname,b.sumqty as squantity,b.beforemoney as oldprice,b.zheshu as discount,b.price as sprice,b.money as amount,b.taxlv as taxrate,b.taxmoney,b.sumtax,b.ispresent as taxamt,b.remark as vrtotal from xs_bjinfo as b"
 +" inner join materialzhu as v on v.ProdId=b.prodid"
 +" where b.billno='20160501001' ")
	public List<Xs_dd> queryxsbjinfo(); 
	
	//查询订单
	@Select("select * from salesorder where Billno=#{Billno}")
	Xs_dd selectxsdd(@Param("Billno") String Billno);
	
	//历史交易查询
	@Select("select * from salesorder as a"
 +" inner join salesorderinfo as b on a.Billno=b.Billno"
 +" where permittersign='已审核'")
	public List<Xs_dd> lsjycx();
	
//	//分页
//	@Select("select * from salesorder  LIMIT  0,#{size}")
//	public int queryXs_dd(@Param("size") int size);
	
	
	
}
